# from flask_login import LoginManager,UserMixin
# from db.common import cli
#
#
#
# login_manager = LoginManager()
#
# # 注销等操作需要用到此函数，给flask_login返回一个与缓存中记录的用户id相同的user对象，
# # flask_login通过此用户对象，再执行登出等操作。
# @login_manager.user_loader
# def load_user(userid):
#     user = get_user(userid)
#     return user
# # 定义用户模型，用于flask_login中进行用户对象的存储。
# class User(UserMixin):
#     # def __init__(self,userid,login_name,password,is_admin):
#     #     self.id = userid
#     #     self.login_name = login_name
#     #     self.password = password
#     #     self.is_admin = is_admin
#     #     self.is_authenticated = True
#     #     self.is_active = True
#     #     self.is_anonymous = False
#     def __init__(self,user_id,login_name,password,id_admin,is_active):
#         self.user_id = user_id
#         self.login_name = login_name
#         self.password = password
#         self.id_admin = id_admin
#         self.is_active = is_active
#     def is_authenticated(self):
#         return True
#     def is_active(self):
#         return True
#     def is_anonymous(self):
#         return False
#
#     # 返回用户的唯一id，此函数不能少
#     def get_id(self):
#         return self.user_id
#
# def build_user_class(r):
#     print(type(r))
#     if not r:
#         return None
#     u = User(r['user_id'], r['login_name'], r['password'], r['is_admin'], r['is_active'])
#     print(u)
#     return u
#
# # 从数据库中取出与传参用户名和密码相同的用户，并调用build_user_class返回用户对象
# def get_User(login_name,password):
#     sql = "select user_id, login_name, password, is_admin,is_active from tb_user " \
#           "where login_name = '{}' and password = '{}';".format(login_name, password)
#     r = cli.fetchall(sql)[0]
#     print(r)
#
#     return build_user_class(r)
# # 从数据库中取出与传参用户名和密码相同的用户，并调用build_user_class返回用户对象
# def get_user(userid):
#     sql = "select user_id, login_name, password, is_admin,is_active from tb_user " \
#           "where user_id = '{}' ;".format( userid)
#     r = cli.fetchall(sql)[0]
#     return build_user_class(r)
#
# def get_user_by_user_id(user_id):
#     """
#     :type user_id: str
#     :param user_id:
#     :return:
#     """
#     sql = "select user_id, login_name, password, is_admin,is_active from tb_user where user_id = '{}';".format(user_id)
#     r = cli.fetchone(sql)
#     return build_user_class(r)